home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 July / macformat-026.iso / mac / Shareware City / Developers / video-toolbox-95-01-14-c / VideoToolbox / Demos / TestAssign.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-17  |  4.5 KB  |  143 lines  |  [TEXT/KAHL]

  1. /*
  2. TestAssign.c
  3.  
  4. This is significantly more complicated than it needs to be. The fancy stuff
  5. is merely to put Assign.c through its paces. In particular, if the array a[]
  6. didn't change dimensions from block to block in testAssign1 then we could
  7. read the whole file by a single call to ReadAssignmentFile, instead of
  8. opening the file and making repeated calls to ReadAssignmentBlock, etc.
  9.  
  10. For a good example of the use of Assign, see ReadLuminanceRecord.c.
  11.  
  12. HISTORY:
  13. 8/93    dgp    created this new version, which cobbles together several older versions.
  14. 8/12/93    dgp    updated to work with new Assign.c
  15. 9/8/93    dgp    call Require() and use new AllocateDescriptions.
  16. 9/5/94 dgp removed assumption in printf's that int==short.
  17. */
  18. #include "VideoToolbox.h"
  19. #include <assert.h>
  20. #if MAC_C
  21.     #include "Luminance.h"
  22. #endif
  23. #define PREFERENCES_FOLDER 0
  24. void moreTests(void);
  25. void main(void);
  26.  
  27. typedef struct {
  28.     double *a,logC,viewingDistance;
  29.     long trials;
  30.     char *message;
  31.     unsigned char *m;
  32. } Psychophysics;
  33. Description *DescribePsychophysics(Psychophysics *p);
  34.  
  35. Description *DescribePsychophysics(Psychophysics *p)
  36. {
  37.     Description *d;
  38.     int i;
  39.     
  40.     d=AllocateDescriptions(10);
  41.     i=0;
  42.     d[i++]=Describe(stringType,&p->message,"message",NULL);
  43.     d[i++]=Describe(doubleType,&p->viewingDistance,"viewingDistance",NULL);
  44.     d[i++]=Describe(shortType,&p->trials,"trials",NULL);
  45.     d[i++]=Describe(doubleType,&p->logC,"logC",NULL);
  46.     d[i++]=Describe(unsignedCharPtrType,&p->m,"m",NULL);
  47.     d[i++]=Describe(doublePtrType,&p->a,"a",NULL);
  48.     assert(i<=10);        /*  make sure array was big enough */
  49.     d[i++]=NullDescription();        /*  mark end of array */
  50.     return d;
  51. }
  52.  
  53. void main(void)
  54. {
  55.     Description *d;
  56.     static Psychophysics psychophysics,*p;
  57.     short i,j,flags=assignReportUnknown;
  58.     FILE *stream;
  59.     char filename[]="testAssign1";
  60.     
  61.     Require(0);
  62.     p=&psychophysics;
  63.     d=DescribePsychophysics(p);
  64.     InitializeDescribedVars(d,flags);
  65.     stream=fopen(filename,"r");
  66.     do{
  67.         printf("\n/******** New block ********/\n");
  68.         ReadAssignmentBlock(stream,d,flags);
  69.             /* a real program would do something useful here with the data in p */
  70.             /* instead we fool around with print statements */
  71.             PrintAssignments(stdout,d,flags);
  72.             printf("Now dimensioned as a");
  73.             for(i=0;;i++){
  74.                 j=FindDescribedDim(d,&p->a,i,flags);
  75.                 if(j<=0)break;
  76.                 printf("[%d]",(int)j);
  77.             }
  78.             printf(".\n");
  79.         FreeDescribedPtrVars(d,flags);
  80.     } while(!feof(stream));
  81.     fclose(stream);
  82.     FreeDescribedVars(d,flags);
  83.     FreeDescriptions(d);
  84.     if(0)moreTests();
  85. }
  86. void moreTests(void)
  87. {
  88.     static double logC,maskLogC,viewingDistance,*a,conditionLogC[4],conditionMaskLogC[4];
  89.     short trials,i,flags;
  90.     static char *kindOfTrial,*message,image[1000];
  91.     unsigned char *m;
  92.     Description *d;
  93.     FILE *stream;
  94.     static char filename[]="testAssign2";
  95.     int error;
  96.     static double b[2][2],c[1][2][3];
  97.     
  98.     flags=assignReportUnknown;
  99.     
  100.     printf("\n\n\nMore tests.\n");
  101.     #ifdef _LUMINANCE_
  102.         if(1){
  103.             static LuminanceRecord LR;
  104.             
  105.             // Test ReadLuminanceRecord.c
  106.             if(PREFERENCES_FOLDER)error=OpenPreferencesFolder();
  107.             i=ReadLuminanceRecord("LuminanceRecord1.h",&LR,flags);
  108.             if(PREFERENCES_FOLDER)error=ClosePreferencesFolder();
  109.             if(i<=0)PrintfExit("Couldn't read LuminanceRecord, error %d.\n",(int)i);
  110.             i=WriteLuminanceRecord("LR.h",&LR,flags);
  111.             if(i<=0)PrintfExit("Couldn't write/verify LuminanceRecord, error %d.\n",(int)i);
  112.             printf("ReadLuminanceRecord.c seems to work fine. Created LR.h\n\n");
  113.         }
  114.     #endif
  115.     #if 1
  116.         /* parse testAssign2 */
  117.         d=AllocateDescriptions(14);
  118.         i=0;
  119.         d[i++]=Describe(doublePtrType,&a,"a","array");
  120.         d[i++]=Describe(unsignedCharPtrType,&m,"m","chars");
  121.         d[i++]=DescribeArray(charType,&image,"image","Image data",100L,0L);
  122.         d[i++]=Describe(stringType,&message,"message",NULL);
  123.         d[i++]=Describe(doubleType,&logC,"logC","log contrast");
  124.         d[i++]=Describe(doubleType,&maskLogC,"maskLogC",NULL);
  125.         d[i++]=Describe(stringType,&kindOfTrial,"kindOfTrial",NULL);
  126.         d[i++]=Describe(doubleType,&viewingDistance,"viewingDistance","inches");
  127.         d[i++]=Describe(shortType,&trials,"trials",NULL);
  128.         d[i++]=DescribeArray(doubleType,&b,"b",NULL,2L,2L,0L);
  129.         d[i++]=DescribeArray(doubleType,&c,"c",NULL,1L,2L,3L,0L);
  130.         assert(i<=14);                                /* make sure array was big enough */
  131.         d[i++]=NullDescription();                    /* mark end of array */
  132.         InitializeDescribedVars(d,0);
  133.         stream=fopen(filename,"r");
  134.         ReadAssignmentLine(stream,d
  135.             ,assignHexFloats|assignReportUnknown|assignEchoAssignments);
  136.         FreeDescribedVars(d,0);
  137.         fclose(stream);
  138.         ReadAssignmentFile(filename,d,assignHexFloats|assignReportUnknown);
  139.         PrintAssignments(stdout,d,0);
  140.         FreeDescriptions(d);
  141.     #endif
  142. }
  143.